<template>
  <div>
    <!-- 折扣策略维护 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="qjhDiscountStrategyMaintain"
      :isSelectColumn="false"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle">新增</multiuse-button>
      </template>
    </FilterTable>

    <Drawer :visible.sync="visible" :title="drawerTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList } from '@/api/omFinance/PriceDiscountManage/DiscountStrategyMaintain';
import SonModel from './SonModel';

export default {
  name: 'DiscountStrategyMaintain',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '明细' };

    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      visible: false,
      handleType: '',
      drawerTitle: ''
    };
  },
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    selectChangeHandle(row) {},
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    addHandle() {
      this.handleType = 'add';
      this.formData = {};
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    detailHandle(row) {
      this.handleType = 'show';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '折扣策略名称',
          fieldName: 'policyName',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          filterable: true,
          label: '启用标志',
          fieldName: 'status',
          placeholder: '请选择',
          itemList: this.createDictList('1003')
        },
        {
          type: 'RANGE_DATE',
          label: '生效日期',
          fieldName: 'useDateStart|useDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择'
        },
        {
          type: 'RANGE_DATE',
          label: '失效日期',
          fieldName: 'unUseDateStart|unUseDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择'
        },
        {
          type: 'SELECT',
          label: '审批状态',
          filterable: true,
          fieldName: 'checkStatus',
          placeholder: '请选择',
          itemList: [
            { text: '待提交', value: 60291001 },
            { text: '审核驳回', value: 60291004 }
          ]
        },
        {
          type: 'SELECT',
          label: '动力形式',
          filterable: true,
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '折扣策略名称',
          dataIndex: 'policyName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '生效日期',
          dataIndex: 'startDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '失效日期',
          dataIndex: 'endDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '启用标志',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1003'),
          render: props => {
            return <span>{this.createDictText(props.row.status, '1003')}</span>;
          }
        },
        {
          title: '动力形式',
          dataIndex: 'powerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: props => {
            return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          }
        },
        {
          title: '创建人',
          dataIndex: 'createdByName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审批状态',
          dataIndex: 'checkStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '待提交', value: 60291001 },
            { text: '审核驳回', value: 60291004 }
          ],
          render: props => {
            return <span>{this.createDictText(props.row.checkStatus, '6029')}</span>;
          }
        },
        {
          title: '审批人',
          dataIndex: 'checkPersonName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '审批时间',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审批意见',
          dataIndex: 'auditRemark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
